const log4js = require('koa-log4'),
    path = require('path'),
    fs = require('fs'),
    config = require('config');

let logPath = config.log.path;
let cfg = {
    appenders: {
        out: { type: 'console' },
        error: { type: 'dateFile', filename: path.join(logPath, 'error') },
        default: { type: 'dateFile', filename: path.join(logPath, 'info') },
    },
    categories: {
        default: { appenders: ['out', 'default'], level: 'info' },
        error: { appenders: ['error'], level: 'error' }
    }
};

//mkdir if not exist
fs.existsSync(logPath) || fs.mkdirSync(logPath);
log4js.configure(cfg);
let logger = log4js.getLogger();

module.exports = logger;